﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.Util;
using Com.CMS263.PO;
using Com.CMS263.BLL;

namespace Com.CMS263.Web.manage.ProdAttr
{
    public partial class ProdAttAction : System.Web.UI.Page
    {
        ProdTypeBLL ptbll = new ProdTypeBLL();
        ProdAttributeBLL pabll = new ProdAttributeBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            string op = Request["op"];
            if (op.ToLower().Equals("chuse"))
            {
                int id = Convert.ToInt32(Request["id"]);
                int flag = Convert.ToInt32(Request["flag"]);
                ProdType pt = new ProdType();
                pt = (ProdType)ptbll.FindModelById("ProdType", id);
                if (flag == 1)
                {
                    pt.IsUse = false;
                    Response.Write("no");
                }
                else
                {
                    pt.IsUse = true;
                    Response.Write("yes");
                }
                ptbll.entity = pt;
                ptbll.UpDate();
            }
            else if (op.ToLower().Equals("delpt"))
            {
                int id = Convert.ToInt32(Request["id"]);
                ProdAttributeBLL pabll = new ProdAttributeBLL();
                ProdGoodsAttrBLL pgabll = new ProdGoodsAttrBLL();
                
                
                try
                {
                    int ga = pgabll.GetCountByProdTypeId(id);
                    int pa = pabll.GetCountByProdTypeId(id);
                    int gadel = 0;
                    int padel = 0;
                    if (ga != 0)
                    {
                         gadel = pgabll.DelByProdTypeId(id);
                        if (gadel == 0)
                        {
                            Response.Write("fail");
                        }
                    }
                    if (pa != 0)
                    {
                         padel = pabll.DelByProdTypeId(id);
                        if (padel == 0)
                        {
                            Response.Write("fail");
                        }
                    }
                    ptbll.Delete("ProdType", id);
                    Response.Write("ok");
                }
                catch (Exception)
                {

                    Response.Write("fail");
                }
            }
            else if (op.ToLower().Equals("delprodatt"))
            {
                int id = Convert.ToInt32(Request["id"]);
                ProdGoodsAttrBLL pgbll = new ProdGoodsAttrBLL();
                try
                {
                    int pg = pgbll.GetCountByAttrId(id);
                    int pgdel = 0;
                    if (pg != 0)
                    {
                        pgdel = pgbll.DelByAttrId(id);
                        if (pgdel == 0)
                        {
                            Response.Write("fail");
                        }
                    }
                    ptbll.Delete("ProdAttribute", id);
                    Response.Write("ok");
                }
                catch (Exception)
                {

                    Response.Write("fail");
                }
            }
            else if (op.ToLower().Equals("chnull"))
            {
                int id = Convert.ToInt32(Request["id"]);
                int flag = Convert.ToInt32(Request["flag"]);
                ProdAttribute pa = new ProdAttribute();
                pa = (ProdAttribute)ptbll.FindModelById("ProdAttribute", id);
                if (flag == 1)
                {
                    pa.IsNull = false;
                    Response.Write("no");
                }
                else
                {
                    pa.IsNull = true;
                    Response.Write("yes");
                }
                pabll.entity = pa;
                pabll.UpDate();
            }
            else if (op.ToLower().Equals("chback"))
            {
                int id = Convert.ToInt32(Request["id"]);
                int flag = Convert.ToInt32(Request["flag"]);
                ProdAttribute pa = new ProdAttribute();
                pa = (ProdAttribute)ptbll.FindModelById("ProdAttribute", id);
                if (flag == 1)
                {
                    pa.IsBackShow = false;
                    Response.Write("no");
                }
                else
                {
                    pa.IsBackShow = true;
                    Response.Write("yes");
                }
                pabll.entity = pa;
                pabll.UpDate();
            }
            else if (op.ToLower().Equals("cha"))//PAList查询有没有扩展属性
            {
                ProdAttributeBLL pabll=new ProdAttributeBLL ();
                int id = Convert.ToInt32(Request["id"]);
                int atcoun = pabll.GetCountByProdTypeId(id);
                if (atcoun != 0)
                {
                    Response.Write("you");
                }
                else
                {
                    Response.Write("wu");
                }
            }
            else if (op.ToLower().Equals("pcha"))//ProdTypeAtt查询有没有扩展属性
            {
                ProdGoodsAttrBLL pgbll = new ProdGoodsAttrBLL();
                int id = Convert.ToInt32(Request["id"]);
                int pa = pgbll.GetCountByAttrId(id);
                if (pa != 0)
                {
                    Response.Write("you");
                }
                else
                {
                    Response.Write("wu");
                }
                
            }
        }
          
    }
}
